<script setup lang="ts">
import { ref } from "vue";
import { useExample } from "./hook";
import { PureTableBar } from "@/components/RePureTableBar";
import { useRenderIcon } from "@/components/ReIcon/src/hooks";

import Delete from "@iconify-icons/ep/delete";
import EditPen from "@iconify-icons/ep/edit-pen";
import Search from "@iconify-icons/ep/search";
import Refresh from "@iconify-icons/ep/refresh";
import AddFill from "@iconify-icons/ri/add-circle-line";

defineOptions({
  name: "Injurytime"
});

const formRef = ref();
const {
  form,
  loading,
  columns,
  dataList,
  pagination,
  ExampleDto,
  classList,
  planList,
  stuList,
  PanelVisibleisshow,
  onSearch,
  resetForm,
  PanelVisible,
  handleDelete,
  handleSizeChange,
  handleCurrentChange,
  handleSelectionChange,
  updateExample
} = useExample();
</script>

<template>
  <div class="main">
    <el-form ref="formRef" :inline="true" :model="form" class="bg-bg_color w-[99/100] pl-4 pt-4">
      <el-form-item label="计划名称：" prop="planId">
        <el-select v-model="form.planId" placeholder="请选择计划名称" clearable filterable class="!w-[180px]">
          <el-option v-for="item in planList" :key="item.planId" :label="item.planName" :value="item.planId" />
        </el-select>
      </el-form-item>
      <el-form-item label="班级名称：" prop="classId">
        <el-select v-model="form.classId" placeholder="请选择班级名称" clearable filterable class="!w-[180px]">
          <el-option v-for="item in classList" :key="item.key" :label="item.value" :value="item.key" />
        </el-select>
      </el-form-item>
      <el-form-item label="操作用户：" prop="userId">
        <el-select v-model="form.userId" placeholder="请选择操作用户" clearable filterable class="!w-[180px]">
          <el-option v-for="item in stuList" :key="item.key" :label="item.value" :value="item.key" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" :icon="useRenderIcon(Search)" :loading="loading" @click="onSearch">
          搜索
        </el-button>
        <el-button :icon="useRenderIcon(Refresh)" @click="resetForm(formRef)">
          重置
        </el-button>
      </el-form-item>
    </el-form>

    <el-dialog v-model="PanelVisibleisshow" title="添加补时" width="30%" center :close-on-click-modal="false">
      <el-form label-position="left" label-width="100px" :model="ExampleDto" style="
            max-width: 460px;
            display: flex;
            justify-content: center;
            align-content: center;
            flex-wrap: wrap;
          ">
        <el-form-item label="计划名称：" prop="RoleType">
          <el-select v-model="form.planId" placeholder="请选择计划名称" clearable filterable class="!w-[180px]">
            <el-option v-for="item in planList" :key="item.planId" :label="item.planName" :value="item.planId" />
          </el-select>
        </el-form-item>
        <el-form-item label="班级名称：" prop="RoleType">
          <el-select v-model="form.classId" placeholder="请选择班级名称" clearable filterable class="!w-[180px]">
            <el-option v-for="item in classList" :key="item.key" :label="item.value" :value="item.key" />
          </el-select>
        </el-form-item>
        <el-form-item label="操作用户：" prop="RoleType">
          <el-select v-model="form.userId" placeholder="请选择操作用户" clearable filterable class="!w-[180px]">
            <el-option v-for="item in stuList" :key="item.key" :label="item.value" :value="item.key" />
          </el-select>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button type="primary" @click="updateExample()"> 保存 </el-button>
          <el-button @click="PanelVisibleisshow = false">取消</el-button>
        </span>
      </template>
    </el-dialog>

    <PureTableBar title="补时管理" @refresh="onSearch" class="h100-60">
      <template #buttons>
        <el-button type="primary" :icon="useRenderIcon(AddFill)" @click="PanelVisible(0)">
          添加
        </el-button>
      </template>
      <template v-slot="{ size, checkList }">
        <pure-table border align-whole="center" showOverflowTooltip table-layout="auto" :loading="loading" :size="size"
          :data="dataList" :columns="columns" :checkList="checkList" :pagination="pagination"
          :paginationSmall="size === 'small' ? true : false" :header-cell-style="{
            background: 'var(--el-table-row-hover-bg-color)',
            color: 'var(--el-text-color-primary)'
          }" @selection-change="handleSelectionChange" @size-change="handleSizeChange"
          @current-change="handleCurrentChange">
          <template #operation="{ row }">
            <el-button class="reset-margin" link type="primary" :size="size" :icon="useRenderIcon(EditPen)"
              @click="PanelVisible(row)">
              修改
            </el-button>
            <el-popconfirm title="是否确认删除?" @confirm="handleDelete(row)">
              <template #reference>
                <el-button class="reset-margin" link type="danger" :size="size" :icon="useRenderIcon(Delete)">
                  删除
                </el-button>
              </template>
            </el-popconfirm>
          </template>
        </pure-table>
      </template>
    </PureTableBar>
  </div>
</template>

<style scoped lang="scss">
:deep(.el-dropdown-menu__item i) {
  margin: 0;
}
</style>
